from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.


class UserModel(AbstractUser):
    phone = models.CharField(max_length=11)

    class Meta:
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class OauthModel(models.Model):
    SITE_TYPE_CHOICES = (
        (1, '微博'),
        (2, '微信'),
        (3, 'QQ')
    )
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, null=True, blank=True, verbose_name='关联用户')
    uid = models.CharField(max_length=120, verbose_name='第三方uid')
    site_type = models.SmallIntegerField(choices=SITE_TYPE_CHOICES, verbose_name='第三方类型')

    class Meta:
        verbose_name = '第三方表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.site_type


class AreaInfoModel(models.Model):
    name = models.CharField(max_length=20, verbose_name='地区')
    pid = models.ForeignKey('self', on_delete=models.CASCADE, null=True, verbose_name='所属地区')

    class Meta:
        verbose_name = '地区表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class AddressModel(models.Model):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='所属用户')
    consignee = models.CharField(max_length=30, verbose_name='收货人')
    province = models.ForeignKey(AreaInfoModel, on_delete=models.CASCADE, related_name='province', verbose_name='省')
    city = models.ForeignKey(AreaInfoModel, on_delete=models.CASCADE, related_name='city', verbose_name='市')
    county = models.ForeignKey(AreaInfoModel, on_delete=models.CASCADE, related_name='county', verbose_name='县')
    detail = models.CharField(max_length=100, verbose_name='详细地址')
    phone = models.CharField(max_length=11, verbose_name='手机号')
    email = models.EmailField(null=True, blank=True)
    is_default = models.BooleanField(default=0, verbose_name='是否默认')

    class Meta:
        verbose_name = '收货地址表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.consignee
